<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>02_JS流程控制</title>
</head>
<body>
<script>
    //1.顺序结构
    console.log('1')
    console.log('2')
    console.log('3')
    //2.分支结构
    let username = 'rose';
    if (!username){
        alert('用户名不能为空!')
    }else {
        alert('欢迎'+username+'回归!');
    }
    //3.选择分支
    let gender = 1 ;
    switch (gender){
        case 1:
            console.log('男');
            break;
        case 0:
            console.log('女');
            break;
        default:
            console.log('未知');
    }
    //4.循环结构
    let names = ['张三','李四','王五','赵六','苟七'];
    for (var i = 0;i<names.length;i++){
        console.log(names[i]);
    }
    //如果使用var定义变量i，循环结束后在此处仍然可以打印i的值
    // 但是如果使用let定义，就会报错：变量i不存在！
    console.log(i);

    //增强for循环
    //let name 表示 遍历 names
    for (let name of names){
        console.log(name);
    }
</script>
</body>
</html>